#include<graphics.h>
#include<cmath>
#include "E_Point.h"
#include "E_Transform.h"
#include <iostream>
using namespace std;
#define PI 3.1415926
#define N 11
double R = 200;
int OriginX = 250, OriginY = 250;
int Width = 800, Height = 500;
int main() {
	HWND hwnd = initgraph(Width, Height);
	setbkcolor(WHITE);
	cleardevice();
	setorigin(OriginX, OriginY);
	setaspectratio(1, -1);
	setlinecolor(RED);
	setlinestyle(PS_SOLID, 2);
	E_Point P[N * 2 + 1];
	E_Transform Translate;
	double dx = 2, dy = 2;
	int k = 0;
	for (double i = 0; i < 2 * PI; i += PI / N, k++) {
		P[k].x = R * cos(i);
		P[k].y = R * sin(i);
		
	}
	P[22].x = 0;
	P[22].y = 0;
	Translate.SetMatrix(P, 2 * N + 1);
	while (true) {
		BeginBatchDraw();
		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 2 * N; j++) {
				moveto(P[i].x, P[i].y);
				lineto(P[j].x, P[j].y);
			}
		}
		FlushBatchDraw();
		Sleep(50);
		EndBatchDraw();
		cleardevice();
		
		
		if (P[22].x + R >= Width - OriginX || P[22].x - R <= -OriginX) {
			dx = -dx;
		}
		if (P[22].y + R >= OriginY || P[22].y - R <= -OriginY) {
			dy = -dy;
		}
		Translate.E_Translate(dx, dy);
		Translate.E_Rotate(PI / 3, P[22]);
	}
	
	_getwch();
	closegraph();
	return 0;
}